package com.groupbuying.customer.controller;

import com.groupbuying.customer.constants.CommonConstants;
import com.groupbuying.customer.domain.CustomerPrizeDO;
import com.groupbuying.customer.service.CustomerPrizeService;
import com.groupbuying.customer.utils.PageUtils;
import com.groupbuying.customer.utils.Query;
import com.groupbuying.customer.utils.apiresult.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 中奖表
 * 
 * @author gaoruijun
 * @email 18511893135@163.com
 * @date 2019-07-30 10:25:17
 */
 
@RestController
@RequestMapping("/customerPrize")
public class CustomerPrizeController {
	@Autowired
	private CustomerPrizeService customerPrizeService;

	/**
	 * @api {post} /customerPrize/list 获取中奖列表
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:37
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader {String} Authorization 用户授权token
	 * @apiParam {String} uuid 唯一标识
	 * @apiParam {String} delflag 删除标记
	 * @apiParam {String} gmtTime 中奖时间
	 * @apiParam {String} type:中奖类型 摇号-rock-1,转盘-turn-2
	 * @apiParam {String} source 获奖来源
	 * @apiParam {String} customerId 会员uuid
	 * @apiParam {String} prize 奖品名称
	 * @apiParam {String} openId 微信单公众号标示
	 * @apiParam {String} wxNikeName 微信昵称
	 * @apiParam {String} mobile 用户手机号
	 * @apiSuccess {Object} PageUtils 返回参数
	 */
	@PostMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<CustomerPrizeDO> customerPrizeList = customerPrizeService.list(query);
		int total = customerPrizeService.count(query);
		PageUtils pageUtils = new PageUtils(customerPrizeList, total);
		return pageUtils;
	}

	/**
	 * @api {post} /customerPrize/wxRegistForPrize 马拉松用户登陆
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:41
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader {String} Authorization 用户授权token
	 * @apiParam {String} wxCode 微信用户授权code
	 * @apiParam {String} openid 微信用户ID
	 * @apiSuccess {ApiResult} success 登录成功
	 * @apiSuccess {ApiResult} failure 请求access_token失败
	 */
	@PostMapping("/wxRegistForPrize")
	public ApiResult wxRegistForPrize(@RequestParam Map<String,Object> map){
		return customerPrizeService.wxRegistForPrize(map);
	}

	/**
	 * @api {post} /customerPrize/savaPrizeMessage 保存用户中奖信息
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:43
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader {String} Authorization 用户授权token
	 * @apiParam {String} type 中奖类型:摇号-rock-1,转盘-turn-2
	 * @apiParam {String} prize 奖品名称
	 * @apiParam {String} mobile 用户手机号
	 * @apiParam {String} source 获奖来源
	 * @apiParam {String} identifi 奖品标识
	 * @apiSuccess {ApiResult} failure 正在抽奖中
	 * @apiSuccess {ApiResult} success 保存成功
	 */
	@PostMapping("/savaPrizeMessage")
	public ApiResult savaPrizeMessage(@RequestParam  Map<String,String> map){
		return  customerPrizeService.savaPrizeMessage(map);
	}

	/**
	 * @api {post} /customerPrize/getAllPrize 获取所有中奖信息
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:45
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader {String} Authorization 用户授权token
	 * @apiParam {String} source 获奖来源
	 * @apiSuccess {ApiResult} success 请求成功
	 */
	@PostMapping("/getAllPrize")
	public  ApiResult getAllPrize(@RequestParam("source") String source){
        Map<String,Object> map = new HashMap<>();
        List<CustomerPrizeDO> prizeDetails = customerPrizeService.getPrizeDetails(source);
        map.put("prizeDetails",prizeDetails);
        map.put("code","1");
       return ApiResult.success(map);
    }

	/**
	 * @api {post} /customerPrize/screenPrize 大屏幕抽奖
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:46
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader {String} Authorization 用户授权token
	 * @apiParam {String} type 中奖类型
	 * @apiSuccess {ApiResult} success 请求成功
	 * @apiSuccess {ApiResult} failure 请求失败
	 */
	@PostMapping("/screenPrize")
	public ApiResult screenPrize(){
		return customerPrizeService.getMessageBytype(CommonConstants.MLS);

	}

	/**
	 * @api {post} /customerPrize/sumPrize 中奖数量查询总数
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:48
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader {String} Authorization 用户授权token
	 * @apiParam {String} source 获奖来源
	 * @apiSuccess {String} detaile 各个奖品数量
	 * @apiSuccess {String} all 各个奖品数量
	 */
	@PostMapping("/sumPrize")
	public Map<String, Object> sumPrize(@RequestParam Map<String,String>map){
		return customerPrizeService.sumPrize(map);
	}

	/**
	 * @api {get} /customerPrize/countCustomerForMls 查询马拉松用户
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:49
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader {String} Authorization 用户授权token
	 * @apiParam {String} null 无
	 * @apiSuccess {int} count 够样优店用户表总数
	 */
	@GetMapping("/countCustomerForMls")
	public  Integer countCustomerForMls(){
		return customerPrizeService.countCustomerForMls();
	}

	/**
	 * @api {get} /customerPrize/sumEvenPrize 获取中奖来源中奖数量
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:51
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader {String} Authorization 用户授权token
	 * @apiParam {String} null 无
	 * @apiSuccess {String} doll 娃娃机
	 * @apiSuccess {String} rubbish 垃圾分类
	 * @apiSuccess {String} market 模拟超市
	 * @apiSuccess {String} rock 摇号
	 */
	@GetMapping("/sumEvenPrize")
	public  Map<String,Integer> sumEvenPrize(){
		return customerPrizeService.sumEvenPrize();
	}

	/**
	 * @api {get} /customerPrize/getPrizeFormSource 转盘详情
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:53
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader {String} Authorization 用户授权token
	 * @apiParam {String} source 获奖来源
	 * @apiSuccess {List} List<CustomerPrizeDO> 转盘详情
	 */
	@GetMapping("/getPrizeFormSource")
	public List getPrizeFormSource(@RequestParam("source") String source){
		return customerPrizeService.getPrizeFormSource(source);
	}

	/**
	 * @api {get} /customerPrize/getPrizeFormType 大屏幕抽奖详情
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:55
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader {String} Authorization 用户授权token
	 * @apiParam {String} type 中奖类型:摇号-rock-1,转盘-turn-2
	 * @apiSuccess {List} List<CustomerPrizeDO> 大屏幕抽奖详情
	 */
	@GetMapping("/getPrizeFormType")
	public List getPrizeFormType(@RequestParam("type") String type){
		return customerPrizeService.getPrizeFormType(type);
	}

	/**
	 * @api {post} /customerPrize/saveScreen 投屏中奖信息保存
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:56
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader  Authorization 用户授权token
	 * @apiParam {String} type 中奖类型:摇号-rock-1,转盘-turn-2
	 * @apiParam {String} mobile 用户手机号
	 * @apiSuccess {ApiResult} success 保存成功
	 */
	@PostMapping("saveScreen")
	public  ApiResult saveScreen(@RequestParam Map<String,String> map){
		return customerPrizeService.saveScreen(map);
	}

	/**
	 * @api {post} /customerPrize/getTimeBySourceAndCustomerId 查询次数
	 * @apiExample
	 * author yangmeng
	 * tar TODO 未知调用方
	 * date 2019/10/31 14:58
	 * @apiGroup bus-customer
	 * @apiVersion 1.0.0
	 * @apiHeader {String} Authorization 用户授权token
	 * @apiParam {map} map 总次数
	 * @apiSuccess {ApiResult} failure 请求失败，每人只允许1次抽奖
	 * @apiSuccess {ApiResult} success 请求成功
	 */
	@PostMapping("/getTimeBySourceAndCustomerId")
	public ApiResult getTimeBySourceAndCustomerId(@RequestParam Map<String,String> map){
		return customerPrizeService.getTimeBySourceAndCustomerId(map);
	}
}


